package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigInteger;

/**
 * 整数范围
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexIntegerRange extends LatexNumberRange {
    /**
     * 起始整数
     */
    private BigInteger begin;

    /**
     * 结束整数
     */
    private BigInteger end;


    public String getLatex() {
        return String.format("%d-%d", begin, end);
    }

    public LatexIntegerRange(BigInteger begin, BigInteger end) {
        this.begin = begin;
        this.end = end;
    }

    public LatexIntegerRange(String beginValueText, String endValueText) {
        this.begin = ParseHelper.parseBigInteger(beginValueText);
        this.end = ParseHelper.parseBigInteger(endValueText);
    }

    public LatexIntegerRange(String rangeText) {
        var array = ParseHelper.parseString(rangeText, "-").toArray();
        this.begin = ParseHelper.parseBigInteger((String) array[0]);
        this.end = ParseHelper.parseBigInteger((String) array[1]);
    }
}
